package com.ywq.app.dao.impl;
import java.util.List;
import java.util.Map;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ywq.app.dao.ArtistDao;
import com.ywq.app.domain.AdminUser;
import com.ywq.app.domain.ArtArtist;
import com.ywq.app.domain.ArtArtistPic;
import com.ywq.app.domain.ArtMade;
import com.ywq.app.domain.ArtMadeAudit;
import com.ywq.app.domain.ArtMadeTalk;
import com.ywq.app.domain.ArtMap;
import com.ywq.app.domain.ArtPic;
import com.ywq.app.domain.PicComment;
import com.ywq.app.domain.PwSchool;
import com.ywq.common.exception.AppBusinessException;


public class ArtistDaoImpl extends SqlSessionDaoSupport implements ArtistDao{
	
	private static final Logger logger = LoggerFactory.getLogger(ArtPicDaoImpl.class);
	//添加艺术家
	@Override
	public void insertArtArtist(ArtArtist artArtist) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("com.ywq.app.persistence.ArtArtistMapper.insertArtist",
							artArtist);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertArtPic user failure.", e);
			}
			throw new AppBusinessException("insertArtPic user failure.", e);
		}
	}
	//更改艺术家
	@Override
	public void updateArtist(ArtArtist artArtist) throws AppBusinessException {
		try {
			getSqlSession()
					.update("com.ywq.app.persistence.ArtArtistMapper.updateArtist",
							artArtist);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertArtPic user failure.", e);
			}
			throw new AppBusinessException("insertArtPic user failure.", e);
		}
	}
	
	/**
	 *艺术家总数
	 */
	@Override
	public int getArtistListCount(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getArtistListCount",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtistListCount user failure.", e);
			}
			throw new AppBusinessException("getArtistListCount user failure.", e);
		}
	}
	@Override
	public int getArtistListCsCount(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getArtistListCsCount",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtistListCount user failure.", e);
			}
			throw new AppBusinessException("getArtistListCount user failure.", e);
		}
	}
	/**
	 * 展览馆列表
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtArtist> getArtistList(Map<String, Object> map) throws AppBusinessException {

		try {
			return getSqlSession()
					.selectList(
							"com.ywq.app.persistence.ArtArtistMapper.getArtistList",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtistList list failure.", e);
			}
			throw new AppBusinessException("getArtistList list failure.", e);
		}
	}
	//某艺术家艺术画数 
	@Override
	public int getArtistPicListCount(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getArtistPicListCountByIstId",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtistListCount user failure.", e);
			}
			throw new AppBusinessException("getArtistListCount user failure.", e);
		}
	}
	/**
	 * 定制订单列表 总数
	 */
	@Override
	public int getMadeOrderListCount(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getMadeOrderListCount",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getMadeOrderListCount user failure.", e);
			}
			throw new AppBusinessException("getMadeOrderListCount user failure.", e);
		}
	}
	//定制订单列表
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtMade> getMadeOrderList(Map<String, Object> map) throws AppBusinessException {
		try {
			return getSqlSession() .selectList( "com.ywq.app.persistence.ArtArtistMapper.getMadeOrderList",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getMadeOrderList list failure.", e);
			}
			throw new AppBusinessException("getMadeOrderList list failure.", e);
		}
	}
	
	//某艺术家艺术画列表
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtArtistPic> getArtistPicList(Map<String, Object> map) throws AppBusinessException {
		try {
			return getSqlSession() .selectList( "com.ywq.app.persistence.ArtArtistMapper.getArtistPicList",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtistPicList list failure.", e);
			}
			throw new AppBusinessException("getArtistPicList list failure.", e);
		}
	}
	@Override
	public int getAllPicNumByArtistId(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getAllPicNumByArtistId",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getAllPicNumByArtistId user failure.", e);
			}
			throw new AppBusinessException("getAllPicNumByArtistId user failure.", e);
		}
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtArtist> getMadeArtistCsList(Map<String, Object> map) throws AppBusinessException {

		try {
			return getSqlSession()
					.selectList(
							"com.ywq.app.persistence.ArtArtistMapper.getMadeArtistCsList",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getMadeArtistCsList list failure.", e);
			}
			throw new AppBusinessException("getMadeArtistCsList list failure.", e);
		}
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtPic> getFourPicMadeByClass(Map<String, Object> map) throws AppBusinessException {

		try {
			return getSqlSession()
					.selectList(
							"com.ywq.app.persistence.ArtArtistMapper.getFourPicMadeByClass",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getFourPicMadeByClass list failure.", e);
			}
			throw new AppBusinessException("getFourPicMadeByClass list failure.", e);
		}
	}
	/**
	 * 艺术家列表
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtArtist> getMadeArtistList(Map<String, Object> map) throws AppBusinessException {

		try {
			return getSqlSession()
					.selectList(
							"com.ywq.app.persistence.ArtArtistMapper.getMadeArtistList",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtistList list failure.", e);
			}
			throw new AppBusinessException("getArtistList list failure.", e);
		}
	}
	/**
	 * 艺术家详情
	 */
	@Override
	public ArtArtist getArtist(Map<String, Object> map)throws AppBusinessException {

		try {
			return (ArtArtist) getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getArtistById",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtist list failure.", e);
			}
			throw new AppBusinessException("getArtist list failure.", e);
		}
	}
	/**
	 * 添加定制订单
	 */
	@Override
	public void insterMade(ArtMade artMade) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("com.ywq.app.persistence.ArtArtistMapper.insterMade",
							artMade);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insterMade user failure.", e);
			}
			throw new AppBusinessException("insterMade user failure.", e);
		}
	}

	//对话列表
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtMadeTalk> getTalkListByMadeId(Map<String, Object> map) throws AppBusinessException {
		try {
			return getSqlSession() .selectList( "com.ywq.app.persistence.ArtArtistMapper.getTalkListByMadeId",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getTalkListByMadeId list failure.", e);
			}
			throw new AppBusinessException("getTalkListByMadeId list failure.", e);
		}
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtMadeTalk> getTalkGrid(Map<String, Object> map) throws AppBusinessException {
		try {
			return getSqlSession() .selectList( "com.ywq.app.persistence.ArtArtistMapper.getTalkGrid",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getTalkListByMadeId list failure.", e);
			}
			throw new AppBusinessException("getTalkListByMadeId list failure.", e);
		}
	}
	@Override
	public int getTalkGridCount(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getTalkGridCount",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getTalkGridCount user failure.", e);
			}
			throw new AppBusinessException("getTalkGridCount user failure.", e);
		}
	}
	
	//定制订单的详情
	@Override
	public ArtMade getArtMadeById(Map<String, Object> map)throws AppBusinessException {

		try {
			return (ArtMade) getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getArtMadeById",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtist list failure.", e);
			}
			throw new AppBusinessException("getArtist list failure.", e);
		}
	}
	
	//定制付款订单的
	@Override
	public ArtMadeAudit getArtMadeAuditById(Map<String, Object> map)throws AppBusinessException {

		try {
			return (ArtMadeAudit) getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getArtMadeAuditById",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtMadeAuditById list failure.", e);
			}
			throw new AppBusinessException("getArtMadeAuditById list failure.", e);
		}
	}
	//某审核单
	@Override
	public ArtMadeAudit getMadeAuditByAuditId(Map<String, Object> map)throws AppBusinessException {

		try {
			return (ArtMadeAudit) getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getMadeAuditByAuditId",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtist list failure.", e);
			}
			throw new AppBusinessException("getArtist list failure.", e);
		}
	}
	
	//添加对话
	@Override
	public void insertArtMadeTalk(ArtMadeTalk artMadeTalk) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("com.ywq.app.persistence.ArtArtistMapper.insertArtMadeTalk",
							artMadeTalk);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insterMade user failure.", e);
			}
			throw new AppBusinessException("insterMade user failure.", e);
		}
	}
	//保存审批
	@Override
	public void insertMadeAudit(ArtMadeAudit artMadeAudit) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("com.ywq.app.persistence.ArtArtistMapper.insertMadeAudit",
							artMadeAudit);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertMadeAudit user failure.", e);
			}
			throw new AppBusinessException("insertMadeAudit user failure.", e);
		}
	}
	//所有的审批
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtMadeAudit> getArtMadeAuditGrid(Map<String, Object> map) throws AppBusinessException {
		try {
			return getSqlSession() .selectList( "com.ywq.app.persistence.ArtArtistMapper.getMadeAudit",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtMadeAuditGrid list failure.", e);
			}
			throw new AppBusinessException("getArtMadeAuditGrid list failure.", e);
		}
	}	
	@Override
	public int getMadeAuditCount(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getMadeAuditCount",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getMadeAuditCount user failure.", e);
			}
			throw new AppBusinessException("getMadeAuditCount user failure.", e);
		}
	}
	//某订单的审批
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtMadeAudit> getMadeAuditByMadeId(Map<String, Object> map) throws AppBusinessException {
		try {
			return getSqlSession() .selectList( "com.ywq.app.persistence.ArtArtistMapper.getMadeAuditByMadeId",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getMadeAuditByMadeId list failure.", e);
			}
			throw new AppBusinessException("getMadeAuditByMadeId list failure.", e);
		}
	}
	//
	@Override
	public void updateMadeStage(Map<String, Object> map) throws AppBusinessException {
		try {
			getSqlSession()
					.update("com.ywq.app.persistence.ArtArtistMapper.updateMadeStage",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insterMade user failure.", e);
			}
			throw new AppBusinessException("insterMade user failure.", e);
		}
	}
	@Override
	public void updateMadePay(ArtMade artMade) throws AppBusinessException {
		try {
			getSqlSession()
					.update("com.ywq.app.persistence.ArtArtistMapper.updateMadePay",
							artMade);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("updateMadePay user failure.", e);
			}
			throw new AppBusinessException("updateMadePay user failure.", e);
		}
	}
	
	//审核通过
	@Override
	public void passMadeAudit(Map<String, Object> map) throws AppBusinessException {
		try {
			getSqlSession()
					.update("com.ywq.app.persistence.ArtArtistMapper.passMadeAudit",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("passMadeAudit user failure.", e);
			}
			throw new AppBusinessException("passMadeAudit user failure.", e);
		}
	}
	//
	//联想公司名称
	@SuppressWarnings("unchecked")
	@Override
	public List<PwSchool> getCompanyByName(Map<String,Object> map)
			throws AppBusinessException {
		try {
			return getSqlSession()
					.selectList("com.ywq.app.persistence.ArtArtistMapper.getCompanyByName",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getCompanyByName database failure.", e);
			}
			throw new AppBusinessException("getCompanyByName database failure.", e);
		}
	}
	//学校
	@Override
	public PwSchool getSchool(Map<String, Object> map)throws AppBusinessException {

		try {
			return (PwSchool) getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getSchool",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getSchool list failure.", e);
			}
			throw new AppBusinessException("getSchool list failure.", e);
		}
	}
	//发现的作品
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtPic> getFindPicList(Map<String,Object> map)throws AppBusinessException {
		try {
			return getSqlSession().selectList("com.ywq.app.persistence.ArtArtistMapper.getFindPicList",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getFindPicList database failure.", e);
			}
			throw new AppBusinessException("getFindPicList database failure.", e);
		}
	}
	//发现作品的总数
	@Override
	public int getFindPicListCount(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getFindPicListCount",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getFindPicListCount user failure.", e);
			}
			throw new AppBusinessException("getFindPicListCount user failure.", e);
		}
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtMap> getNumByCtiy()throws AppBusinessException {
		try {
			return getSqlSession().selectList("com.ywq.app.persistence.ArtArtistMapper.getNumByCtiy");
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getFindPicList database failure.", e);
			}
			throw new AppBusinessException("getFindPicList database failure.", e);
		}
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<PicComment> getFindCommentByPicId(Map<String,Object> map)throws AppBusinessException {
		try {
			return getSqlSession().selectList("com.ywq.app.persistence.ArtArtistMapper.getFindCommentByPicId",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getFindCommentByPicId database failure.", e);
			}
			throw new AppBusinessException("getFindCommentByPicId database failure.", e);
		}
	}
	@Override
	public int getFindCommentCountByPicId(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getFindCommentCountByPicId",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getFindCommentCountByPicId user failure.", e);
			}
			throw new AppBusinessException("getFindCommentCountByPicId user failure.", e);
		}
	}
	@Override
	public ArtArtist getAllCountByArtistId(Map<String, Object> map)throws AppBusinessException {
		try {
			return (ArtArtist) getSqlSession().selectOne("com.ywq.app.persistence.ArtArtistMapper.getAllCountByArtistId",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getAllCountByArtistId list failure.", e);
			}
			throw new AppBusinessException("getAllCountByArtistId list failure.", e);
		}
	}
	
	
	@Override
	public void insertComment(PicComment picComment) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("com.ywq.app.persistence.ArtArtistMapper.insertComment",
							picComment);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertComment user failure.", e);
			}
			throw new AppBusinessException("insertComment user failure.", e);
		}
	}
	
	//一级分类的作品
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtPic> getPrintPicList(Map<String,Object> map)throws AppBusinessException {
		try {
			return getSqlSession().selectList("com.ywq.app.persistence.ArtArtistMapper.getPrintPicList",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getPrintPicList database failure.", e);
			}
			throw new AppBusinessException("getPrintPicList database failure.", e);
		}
	}
	//一级分类作品的总数
	@Override
	public int getPrintPicListCount(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getPrintPicListCount",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getPrintPicListCount user failure.", e);
			}
			throw new AppBusinessException("getPrintPicListCount user failure.", e);
		}
	}
	///
	@Override
	public ArtArtistPic getArtArtistPicByPicId(Map<String, Object> map)throws AppBusinessException {

		try {
			return (ArtArtistPic) getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getArtArtistPicByPicId",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getSchool list failure.", e);
			}
			throw new AppBusinessException("getSchool list failure.", e);
		}
	}
	//根据artistId查艺术家名称
	@Override
	public AdminUser getUserByArtistId(String artistId) throws AppBusinessException {
		try {
			return (AdminUser) getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtArtistMapper.getUserByArtistId",
							artistId);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Get user failure.", e);
			}
			throw new AppBusinessException("Get user failure.", e);
		}
	}
}
